//
//  JMBrandGroup.m
//  OpenSesame
//
//  Created by 张家铭 on 16/1/3.
//  Copyright © 2016年 OpenSesame. All rights reserved.
//

#import "JMBrandGroup.h"
#import "JMBrand.h"
#define CARList @"http://47.92.139.238/copying/index/carList"
@implementation JMBrandGroup

- (instancetype)initWithDic:(NSDictionary *)dic {
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dic];
        NSMutableArray *brandArr = [NSMutableArray array];
        for (NSDictionary *dict in self.brands) {
            JMBrand *brand = [JMBrand brandWithDic:dict];
            [brandArr addObject:brand];
        }
        self.brands = brandArr;
        
    }
    return self;
}

+ (instancetype)brandGroupWithDic:(NSDictionary *)dic {
    return [[self alloc] initWithDic:dic];
}

+ (NSArray *)brandGroupsList {
    // 加载json文件
    NSString *path = [[NSBundle mainBundle] pathForResource:@"car.json" ofType:nil];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSArray *dictArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//
//    NSUserDefaults *defult =[NSUserDefaults standardUserDefaults];
//    
//    WDLog(@"%@",[defult objectForKey:@"token"]);
//    // 字典转模型
//    NSMutableArray *brandArray = [NSMutableArray array];
//    [JMHttpTool post:CARList param:@{@"token":[defult objectForKey:@"token"]} success:^(id responseObject) {
//        
//        NSDictionary *dic =[NSDictionary dictionaryWithDictionary:responseObject];
//        NSMutableArray *dictArray = [NSMutableArray arrayWithArray:dic[@"data"]];
////         NSMutableArray *brandArray = [NSMutableArray array];
////        for (NSDictionary *dict in dictArray) {
////            JMBrandGroup *brands = [JMBrandGroup brandGroupWithDic:dict];
////            [brandArray addObject:brands];
////            
////        }
//
//    } frail:^(NSError *error) {
//        
//    }];
    NSMutableArray *brandArray = [NSMutableArray array];
    for (NSDictionary *dict in dictArray) {
        JMBrandGroup *brands = [JMBrandGroup brandGroupWithDic:dict];
        [brandArray addObject:brands];
        
    }
    
       return brandArray;
}
@end
